package com.linsen.erp.admin.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.linsen.core.common.enums.DeleteType;
import com.linsen.core.common.util.ConvertUtil;
import com.linsen.core.common.util.Result;
import com.linsen.core.log.annotation.Log;
import com.linsen.erp.admin.entity.PositionEntity;
import com.linsen.erp.admin.provider.dto.PositionDTO;
import com.linsen.erp.admin.provider.qo.PositionQo;
import com.linsen.erp.admin.provider.vo.PositionVO;
import com.linsen.erp.admin.service.IPositionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * <p>
 * 岗位 前端控制器
 * </p>
 *
 * @author zhaoyong
 * @since 2024-10-08
 */
@RestController
@RequestMapping("/admin/position")
@Api(tags = "岗位管理")
@RequiredArgsConstructor
public class PositionController {
    private final IPositionService iPositionService;

    //@SaCheckPermission("admin:position:page")
    @PostMapping("/page")
    @ApiOperation(value = "分页查询",response = PositionVO.class)
    public Result page(@RequestBody PositionQo positionQo) {
        return Result.data(this.iPositionService.page(positionQo));
    }

    @GetMapping("/list")
    @ApiOperation(value = "岗位列表",response = PositionVO[].class)
    public Result list() {
        List<PositionEntity> positionEntityList = this.iPositionService.list(
                new LambdaQueryWrapper<PositionEntity>()
                        .eq(PositionEntity::getIsDeleted, DeleteType.NORMAL.getValue())
        );
        return Result.data(ConvertUtil.convert(positionEntityList,PositionVO.class));
    }

    @GetMapping("info")
    @ApiImplicitParam(name = "id", value = "岗位id", required = true, dataType = "string")
    @ApiOperation(value = "岗位详情",response = PositionVO.class)
    public Result get(@ApiIgnore @RequestParam(value = "id") String id) {
        return Result.data(this.iPositionService.get(id));
    }

    //@SaCheckPermission("admin:position:save")
    @Log(value = "新增岗位")
    @PostMapping("save")
    @ApiOperation("新增岗位")
    public Result save(@RequestBody PositionDTO positionDTO) {
        iPositionService.savePosition(positionDTO);

        return Result.ok();
    }

    //@SaCheckPermission("admin:position:update")
    @Log(value = "修改岗位")
    @PostMapping("update")
    @ApiOperation("修改岗位")
    public Result update(@RequestBody PositionDTO positionDTO) {
        iPositionService.updatePosition(positionDTO);

        return Result.ok();
    }

    //@SaCheckPermission("admin:position:delete")
    @Log(value = "删除岗位")
    @PostMapping("delete")
    @ApiImplicitParam(name = "id", value = "岗位id", required = true, dataType = "string")
    @ApiOperation("删除岗位")
    public Result delete(@ApiIgnore @RequestParam("id") String id) {
        iPositionService.delete(id);

        return Result.ok();
    }
}
